package model;

import java.awt.Color;
import java.awt.Graphics;

public class AI {
	
	private int x;
	private int y;

	private Ball ball;
	public static final int SIZE_X = 8;
	public static final int SIZE_Y = 50;
	public static final int MARGIN = 10;

	private static final Color COLOR = Color.WHITE;

	public AI(Ball ball) {
		this.ball = ball;
		this.x = 20;
		this.y = Game.HEIGHT / 2;
	}

	public void move() {
		y = ball.getY();
		handleBoundary();
	}

	public void draw(Graphics g) {
		Color savedCol = g.getColor();
		g.setColor(COLOR);
		g.fillRect(getX() - SIZE_X / 2, getY() - SIZE_Y / 2, SIZE_X, SIZE_Y);
		g.setColor(savedCol);
	}

	protected void handleBoundary() {
		if (y + SIZE_Y / 2 > Game.HEIGHT - MARGIN) {
			y = Game.HEIGHT - SIZE_Y / 2 - MARGIN;
		}
		else if (y - SIZE_Y / 2 < MARGIN) {
			y = SIZE_Y / 2 + MARGIN;
		}
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}
	
}
